import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Tim Hooper
 * @version 1.0
 * @time 2022/09/26/23:49
 */
public class ExcelListener extends AnalysisEventListener<Content> {

    public List<Content> list;

    public ExcelListener(List<Content> list ) {
        this.list = list;
    }

    //一行一行读取excel中的内容，从第二行开始
    @Override
    public void invoke(Content content, AnalysisContext analysisContext) {
        list.add(content);
        System.out.println(content.getRow());
    }

    //读取第一行数据
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        super.invokeHeadMap(headMap, context);
        System.out.println("first column：" + headMap.get(0) + "\t第二列：" + headMap.get(1));
    }

    //读完后执行
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("finish reading！");
        System.out.println("===============================");
    }
}
